<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="root">

    </div>
</body>
<script src="../react@17.js"></script>
<script src="../react-dom@17.js"></script>
<script src="../babel.js"></script>
<script type="text/babel">
    console.log(React)
    // PureComponent 类 自动为组件状态和props做对比是否改变，但是他仅仅是浅对比
    class App extends React.PureComponent{
        state={
            num:1,
            obj:{
                name:"张三",
                age:18,
                list:[1,2,3,4,5]
            },
            list:[1,2,3,4,5,6,7,8,9,10]
        }
        render(){
            console.log("渲染")
            return (
                <div>
                    <h1>{this.state.num}</h1>
                    <button onClick={()=>{
                        this.setState({
                            num:1
                        })
                    }}>点我</button>
                    <h2>{this.state.obj.name}</h2>
                    <button onClick={()=>{
                        // let newObj = {...this.state.obj};
                        // newObj.name='李四'
                        this.state.obj.list.push(10)
                        this.setState({
                            obj: this.state.obj
                        })
                    }}>改变</button>
                    <ol>
                    {
                        this.state.list.map(item=>{
                            return <Li key={item} item={item} />
                        })
                    }    
                    </ol>
                    <button onClick = {()=>{
                         let newList = [...this.state.list]
                         newList[9]=100;
                        this.setState({
                            list:newList
                        })
                    }}>改变10</button>
                </div>
            )
        }
    }
    class Li extends React.PureComponent{
        render(){
            console.log("渲染啦啦啦啦")
            return <li>{this.props.item}</li>
        }
    }
    ReactDOM.render(<App/>,document.getElementById("root"))
</script>
</html>